import nunjuck from 'nunjucks';
import { fileURLToPath } from 'url';
import fs from 'fs';
export const registryTemplate = function () {
    return async (ctx, next) => {
        ctx.render = function (html, obj) {
            let currentFileUrl = import.meta.url;
            let viewsBaseUrl = new URL('../static/views', currentFileUrl);
            let viewsBasePath = fileURLToPath(viewsBaseUrl);

            ctx.body = (nunjuck.configure(viewsBasePath, { noCache: true, watch: true })).render(html, obj);

        }
        await next()
    }
}

export const processStaticResources = function(){
    return async(ctx,next)=>{
        let url = ctx.requset.url;
        if (url.startsWith('/statics')){
            ctx.body = fs.readFileSyns('./${url}')
        }
        await next();
    }
}